package com.example.g5project.repository.repo;

import com.example.g5project.entity.Administrator;
import com.example.g5project.entity.relation.ConsultInfo;
import com.example.g5project.entity.relation.ConsultantMessages;
import com.example.g5project.entity.relation.HelpMessage;
import com.example.g5project.repository.dao.AdministratorDao;
import com.example.g5project.repository.dao.ConsultantHelpMessageDao;
import com.example.g5project.repository.dao.ConsultantMessageDao;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;

/**
 * @author Hu Zirui
 * @version 1.0.0
 * @ClassName AdministratorRepo.java
 * @Description TODO
 * @createTime 2022年03月23日 14:26:00
 */
@Component
@Transactional
public class AdministratorRepo extends Repo<Administrator, Integer> {
    private final AdministratorDao administratorDao;
    private final ConsultantMessageDao consultantMessageDao;
    private final ConsultantHelpMessageDao consultantHelpMessageDao;

    protected AdministratorRepo(JpaRepository<Administrator, Integer> dao, AdministratorDao administratorDao, ConsultantMessageDao consultantMessageDao, ConsultantHelpMessageDao consultantHelpMessageDao) {
        super(dao);
        this.administratorDao = administratorDao;
        this.consultantMessageDao = consultantMessageDao;
        this.consultantHelpMessageDao = consultantHelpMessageDao;
    }

    public Integer getCurrentDateConsultantNumber(String date) {
        return administratorDao.getConsultantNumber(date);
    }

    public Integer getCurrentDateSupervisorNumber(String date) {
        return administratorDao.getSupervisorNumber(date);
    }

    public ArrayList<String> getConsultantInfoByDate(String date) {
        return administratorDao.getConsultantName(date);
    }

    public ArrayList<String> getSupervisorInfoByDate(String date) {
        return administratorDao.getSupervisorName(date);
    }

    public void addConsultantIntoScheduleByID(int id, String date) {
        administratorDao.addConsultantSchedule(id, date);
    }

    public void addSupervisorIntoScheduleByID(int id, String date) {
        administratorDao.addSupervisorSchedule(id, date);
    }

    public void deleteConsultantFromScheduleByID(int id, String date) {
        administratorDao.deleteConsultantSchedule(id, date);
    }

    public void deleteSupervisorFromScheduleByID(int id, String date) {
        administratorDao.deleteSupervisorSchedule(id, date);
    }

    public Integer getConsultantIDByName(String name) {
        return administratorDao.getConsultantID(name);
    }

    public Integer getSupervisorIDByName(String name) {
        return administratorDao.getSupervisorID(name);
    }

    public void bindConsultantAndSupervisor(int consultant_id, int supervisor_id) {
        administratorDao.bind(consultant_id, supervisor_id);
    }

    public void deleteSupervisorFromScheduleByIDAll(Integer id) {
        administratorDao.deleteSupervisorScheduleAll(id);
    }

    public void deleteConsultantFromScheduleByIDAll(Integer id) {
        administratorDao.deleteConsultantScheduleAll(id);
    }

    public ArrayList<String> getSupervisorAllSchedule(Integer id) {
        return administratorDao.getSupervisorAllSchedule(id);
    }

    public ArrayList<String> getConsultantAllSchedule(Integer id) {
        return administratorDao.getConsultantAllSchedule(id);
    }

    public ArrayList<ConsultantMessages> getMessageContentByID(Integer id) {
        return consultantMessageDao.getMessageContent(id);
    }

    public Integer getConsultantMessageID(Integer consultant_id, Integer client_id, String consult_date) {
        return administratorDao.getMessageContentID(consultant_id, client_id, consult_date);
    }

    public ArrayList<HelpMessage> getMessageHelpContentByID(Integer id) {
        return consultantHelpMessageDao.getMessageContent(id);
    }

    public ArrayList<String> getBindRelationship(Integer consultant_id) {
        ArrayList<Integer> supervisor_id = administratorDao.getBindRelationshipID(consultant_id);
        ArrayList<String> result = new ArrayList<>();
        for (Integer id : supervisor_id)
            result.add(administratorDao.getBindRelationship(id));
        return result;
    }

    public void deleteConsultantFromMessageByIDAll(Integer id) {
        administratorDao.deleteConsultantFromMessageByIDAll(id);
    }

    public void deleteConsultantFromBindByIDAll(Integer id) {
        administratorDao.deleteConsultantFromBindByIDAll(id);
    }

    public void deleteSupervisorFromBindByIDAll(Integer id) {
        administratorDao.deleteSupervisorFromBindByIDAll(id);
    }


}
